package willevaluate.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.RotateAnimation;
import android.widget.BaseExpandableListAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.xuegengwang.xuegengwang.R;

import java.util.ArrayList;

import willevaluate.model.QuestionnaireMajorModel;

/**
 * Created by Administrator on 2017/6/8.
 */

public class QuestionnaireMajorAdapter extends BaseExpandableListAdapter {
    private ArrayList<QuestionnaireMajorModel> arrayList;
    private Context context;

    public QuestionnaireMajorAdapter(ArrayList<QuestionnaireMajorModel> arrayList, Context context) {
        this.arrayList = arrayList;
        this.context = context;
    }

    @Override
    public int getGroupCount() {
        return arrayList.size();
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        return arrayList.get(groupPosition).getBeanList().size();
    }

    @Override
    public Object getGroup(int groupPosition) {
        return null;
    }

    @Override
    public Object getChild(int groupPosition, int childPosition) {
        return null;
    }

    @Override
    public long getGroupId(int groupPosition) {
        return groupPosition;
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return childPosition;
    }

    @Override
    public boolean hasStableIds() {
        return true;
    }
    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return true;
    }
    @Override
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
        GroupHolder groupHolder;
        if (convertView == null) {
            groupHolder = new GroupHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.questionniare_major_group, null);
            groupHolder.questionnaire_major_group_arrow = (ImageView) convertView.findViewById(R.id.questionnaire_major_group_arrow);
            groupHolder.questionnaire_major_group_name = (TextView) convertView.findViewById(R.id.questionnaire_major_group_name);
            groupHolder.questionnaire_major_group_count = (TextView) convertView.findViewById(R.id.questionnaire_major_group_count);
            convertView.setTag(groupHolder);
        } else {
            groupHolder = (GroupHolder) convertView.getTag();
        }
        if (isExpanded) {
            groupHolder.questionnaire_major_group_arrow.setImageResource(R.mipmap.more_arrow_down);
        }else{
            groupHolder.questionnaire_major_group_arrow.setImageResource(R.mipmap.more_arrow_right);
        }
        groupHolder.questionnaire_major_group_name.setText(arrayList.get(groupPosition).getName());
        groupHolder.questionnaire_major_group_count.setText("已选" + arrayList.get(groupPosition).getCount() + "个专业");
        return convertView;
    }

    @Override
    public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
        ItemHolder itemHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.questionnaire_major_item, null);
            itemHolder = new ItemHolder();
            itemHolder.questionnaire_major_item_name = (TextView) convertView.findViewById(R.id.questionnaire_major_item_name);
            itemHolder.questionnaire_major_item_ima = (ImageView) convertView.findViewById(R.id.questionnaire_major_item_ima);
            convertView.setTag(itemHolder);
        } else {
            itemHolder = (ItemHolder) convertView.getTag();
        }
        itemHolder.questionnaire_major_item_name.setText(arrayList.get(groupPosition).getBeanList().get(childPosition).getName());
        if (arrayList.get(groupPosition).getBeanList().get(childPosition).isChecked()) {
            itemHolder.questionnaire_major_item_ima.setImageResource(R.mipmap.college_evaluate_checked_ima);
        } else {
            itemHolder.questionnaire_major_item_ima.setImageResource(R.mipmap.college_evaluate_check_ima);
        }
        return convertView;
    }

    private class GroupHolder {
        ImageView questionnaire_major_group_arrow;
        TextView questionnaire_major_group_name;
        TextView questionnaire_major_group_count;
    }

    private class ItemHolder {
        TextView questionnaire_major_item_name;
        ImageView questionnaire_major_item_ima;
    }
}
